package com.rem.web;

import com.google.gson.Gson;
import com.rem.pojo.User;
import jdk.nashorn.internal.parser.TokenType;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author remembrance
 * @version 1.0
 * @date 2021/10/15 16:23
 */
public class AjaxServlet extends BaseServlet{
    protected void getAjax(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("接收到ajax请求");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        User user = new User(1,"user","123","abc");
        Gson gson = new Gson();
        String json = gson.toJson(user);
        resp.getWriter().write(json);

    }

    protected void JQueryAjax(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("接收到ajax请求");
        User user = new User(1,"user","123","abc");
        Gson gson = new Gson();
        String json = gson.toJson(user);
        resp.getWriter().write(json);

    }
}
